<?php
/**
 * Junction_Sql_Expression_PostOrderTraversal
 * 
 * Performs an in order traversal given root node of a tree.
 * 
 * @author Patrick J. Mizer <patrick.mizer@gmail.com>
 */
 
using("Junction_Sql_Expression_Traverser"); 
using("Junction_Sql_Expression_OperandNode"); 
 
class Junction_Sql_Expression_InOrderTraversal 
	implements Junction_Sql_Expression_Traverser 
{
	private $_sqlString;
	
	/**
	 * Performs a post order traversal given root node of a tree.
	 * 
	 * @param Junction_Sql_Expression_Node
	 * 
	 * @return string
	 */
    function traverse(Junction_Sql_Expression_Node $node) 
    {
		if ($node instanceof Junction_Sql_Expression_OperandNode){ 
	    	$this->_sqlString .= $node->getOperand()->getSqlString() . ' ';
	    	
	    	return $this->_sqlString;
	    } else {
	    	$this->_sqlString .= '( ';
			$this->traverse($node->getLeft());
			$this->_sqlString .= $node->getOperator()->getSqlString() . ' ';
			$this->traverse($node->getRight());
	    	$this->_sqlString .= ' ) ';
	    	
	    	return $this->_sqlString;
	    }    	
    }
}
?>